package com.wdh.kjs;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;

import com.wdh.kjs.fragment.HomePageFragment;
import com.wdh.kjs.fragment.InvestmentFragment;
import com.wdh.kjs.fragment.MyAccountFragment;

public class MainActivity extends FragmentActivity {

    public FragmentTabHost mFragmentTabHost;
    private String[] tabTags = {"tab_HomePage", "tab_investment", "tab_myAccountFragment"};
    private Class[] tabFragments = {HomePageFragment.class, InvestmentFragment.class, MyAccountFragment.class};
    private String[] tabTitles = {"首页", "投资", "账户"};
    private int[] tabIcons = {R.drawable.tab_chainwinfinance, R.drawable.tab_investment,R.drawable.tab_myaccount};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        mFragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        mFragmentTabHost.setup(this, getSupportFragmentManager(), R.id.realTabContent);

        for (int i = 0; i < tabFragments.length; i++) {
            TabHost.TabSpec tabSpec = mFragmentTabHost.newTabSpec(tabTags[i]);
            tabSpec.setIndicator(getTabView(i));
            mFragmentTabHost.addTab(tabSpec, tabFragments[i], null);
        }

        mFragmentTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }

    public View getTabView(int i) {
        View view = LayoutInflater.from(this).inflate(R.layout.view_tab_main, null);
        LinearLayout llTab = (LinearLayout) view.findViewById(R.id.ll_mainTab);
        ImageView ivIcon = (ImageView) view.findViewById(R.id.iv_mainTabIcon);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_mainTabTitle);
        ivIcon.setImageResource(tabIcons[i]);
        tvTitle.setText(tabTitles[i]);
        return view;
    }
}
